// $codepro.audit.disable numericLiterals
/**
 * PatientsUI.java
 * @author Suren Nihalani
 */
package edu.gatech.coc.betameisters.userinterfaces;

import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import javax.swing.JButton;
import javax.swing.JTabbedPane;
import javax.swing.JTable;

import edu.gatech.coc.betameisters.infoholders.DoctorsOrders;
import edu.gatech.coc.betameisters.main.DoctorsOffice;
import edu.gatech.coc.betameisters.main.MainPanel;
import edu.gatech.coc.betameisters.people.Patient;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTextField;
import javax.swing.JTextPane;

// TODO: Auto-generated Javadoc
/**
 * The Class PatientsUI.
 * 
 * @author Suren Nihalani
 * @version $REVISION$
 * 
 */
@SuppressWarnings("serial")
public class PatientsUI extends JPanel {

	/** The Patient who will interact with the UI. */
	private Patient myPatient;

	/**
	 * The history of the Patient.
	 */
	private final JTable patientsHistoryTable;

	/** Parent of this UI. Used for shifting screens. */
	@SuppressWarnings("unused")
	private final MainPanel myParent;
	private JTextField textField;

	/**
	 * Create the panel.
	 * 
	 * @param thePatient
	 *            The patient who will interacting with the UI.
	 */
	public PatientsUI(Patient thePatient, final MainPanel p) { // $codepro.audit.disable
															// com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.constructorsOnlyInvokeFinalMethods
		myParent = p;
		myPatient = thePatient;
		final SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
		final JLabel welcomeLabel = new JLabel("Welcome, "
				+ myPatient.toString());
		springLayout.putConstraint(SpringLayout.NORTH, welcomeLabel, 10,
				SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, welcomeLabel, 10,
				SpringLayout.WEST, this);
		add(welcomeLabel);

		final JButton logoutButton = new JButton("Logout");
		logoutButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				myPatient.loggedOut();
				myParent.loginScreen();
			}
		});
		springLayout.putConstraint(SpringLayout.NORTH, logoutButton, 0,
				SpringLayout.NORTH, welcomeLabel);
		springLayout.putConstraint(SpringLayout.EAST, logoutButton, -10,
				SpringLayout.EAST, this);
		add(logoutButton);

		final JTabbedPane historyTabFolder = new JTabbedPane(SwingConstants.TOP);
		springLayout.putConstraint(SpringLayout.NORTH, historyTabFolder, 16, SpringLayout.SOUTH, logoutButton);
		springLayout.putConstraint(SpringLayout.WEST, historyTabFolder, 10,
				SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.SOUTH, historyTabFolder, -16, SpringLayout.SOUTH, this);
		springLayout.putConstraint(SpringLayout.EAST, historyTabFolder, 0,
				SpringLayout.EAST, logoutButton);
		add(historyTabFolder);

		final JPanel histortPanel = new JPanel();
		historyTabFolder.addTab("Options", null, histortPanel, null);
		histortPanel.setLayout(null);

		patientsHistoryTable = new JTable();
		patientsHistoryTable.setBounds(56, 16, 0, 0);
		histortPanel.add(patientsHistoryTable);
				
				JButton btnViewchangeMedicalHistory = new JButton("View/Change Medical History");
				btnViewchangeMedicalHistory.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						p.setMedicalHistory(myPatient, myPatient.getMedHist());
					}
				});
				btnViewchangeMedicalHistory.setBounds(125, 82, 279, 23);
				histortPanel.add(btnViewchangeMedicalHistory);
		
				final JButton requestAppointmentButton = new JButton(
						"Request Appointment");
				requestAppointmentButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
					}
				});
				requestAppointmentButton.setBounds(189, 26, 137, 23);
				histortPanel.add(requestAppointmentButton);
				springLayout.putConstraint(SpringLayout.NORTH,
						requestAppointmentButton, 22, SpringLayout.NORTH, this);
				springLayout.putConstraint(SpringLayout.EAST, requestAppointmentButton,
						-8, SpringLayout.WEST, logoutButton);
				
				textField = new JTextField();
				textField.setEditable(false);
				textField.setBounds(10, 243, 86, 20);
				histortPanel.add(textField);
				textField.setColumns(10);
				
				DoctorsOrders order = thePatient.getMyDocOrders();
				String temp = "";
				if(order == null){
					order = new DoctorsOrders("","","");
				}
				
				JLabel lblYourDoctorsOrder = new JLabel("Your Doctor's Order");
				lblYourDoctorsOrder.setBounds(10, 198, 146, 14);
				histortPanel.add(lblYourDoctorsOrder);
				
				JLabel lblDoctor = new JLabel("Doctor:");
				lblDoctor.setBounds(10, 223, 56, 14);
				histortPanel.add(lblDoctor);
				
				JLabel lblPrescription = new JLabel("Prescription:");
				lblPrescription.setBounds(10, 274, 86, 14);
				histortPanel.add(lblPrescription);
				
				if(order.getPrescriptionOrder() != null){
					temp = order.getPrescriptionOrder().toString();
				}
				JTextPane txtPrescript = new JTextPane();
				txtPrescript.setEditable(false);
				txtPrescript.setText(temp);
				txtPrescript.setBounds(10, 299, 157, 64);
				histortPanel.add(txtPrescript);
				
				JLabel lblTreatment = new JLabel("Treatment:");
				lblTreatment.setBounds(213, 274, 96, 14);
				histortPanel.add(lblTreatment);
				
				temp = "";
				if(order.getTreatmentOrder() != null){
					temp = order.getTreatmentOrder().toString();
				}
				JTextPane txtTreat = new JTextPane();
				txtTreat.setEditable(false);
				txtTreat.setText(temp);
				txtTreat.setBounds(213, 299, 149, 64);
				histortPanel.add(txtTreat);
				
				JLabel lblLabReport = new JLabel("Lab Report:");
				lblLabReport.setBounds(394, 274, 96, 14);
				histortPanel.add(lblLabReport);
				
				temp = "";
				if(order.getLabReport() != null){
					temp = order.getLabReport().toString();
				}
				JTextPane txtLabWork = new JTextPane();
				txtLabWork.setEditable(false);
				txtLabWork.setText(temp);
				txtLabWork.setBounds(392, 299, 165, 64);
				histortPanel.add(txtLabWork);
	}

	/**
	 * Getter for the History of Table.
	 * 
	 * @return The reference to the representing the history of the patient.
	 */
	public JTable getPatientHistoryTable() {
		return patientsHistoryTable;
	}

	/**
	 * Gets the Patient who will interact with the UI.
	 * 
	 * @return the Patient who will interact with the UI
	 */
	public Patient getMyPatient() {
		return myPatient;
	}

	/**
	 * Sets the Patient who will interact with the UI.
	 * 
	 * @param myPatient
	 *            the new Patient who will interact with the UI
	 */
	public void setMyPatient(Patient myPatient) {
		this.myPatient = myPatient;
		repaint();
	}
}
